package org.garbagecan.quartzstudy.listener;

import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

public class Test {

	public static void main(String[] args) throws Exception {
		SchedulerFactory sf = new StdSchedulerFactory();
		Scheduler scheduler = sf.getScheduler();
		
		MyJobListener myJobListener = new MyJobListener("myJobListener");
		scheduler.getListenerManager().addJobListener(myJobListener);

		JobDetail jobDetail1 = JobBuilder.newJob(MyJobProxy.class)
				.withIdentity("myjob1","mygroup1")
				.build();
		Trigger trigger1 = TriggerBuilder.newTrigger()
				.withIdentity("mytrigger1", "mygroup1")
				.startNow()
				.withPriority(5)
				.forJob(jobDetail1)
				.withSchedule(SimpleScheduleBuilder
					.simpleSchedule()
					.withIntervalInSeconds(3)
					.repeatForever())
				.build();
		scheduler.scheduleJob(jobDetail1, trigger1);

		JobDetail jobDetail2 = JobBuilder.newJob(MyJobProxy.class)
				.withIdentity("myjob2","mygroup1").build();
		Trigger trigger2 = TriggerBuilder.newTrigger()
				.withIdentity("mytrigger2", "mygroup1")
				.startNow()
				.withPriority(5)
				.forJob(jobDetail2)
				.withSchedule(SimpleScheduleBuilder
					.simpleSchedule()
					.withIntervalInSeconds(3)
					.repeatForever())
				.build();
		scheduler.scheduleJob(jobDetail2, trigger2);
		
		scheduler.start();
	}

}
